package com.wql.rabbitmq.study;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.QueueingConsumer;
import com.wql.rabbitmq.ChannelFactory;
import com.wql.rabbitmq.Constant;

public class TopicTestForConsumer {

	public static void main(String[] args) throws Exception {
		Channel channel = ChannelFactory.getChannel();
		channel.exchangeDeclare(Constant.TOPIC_NAME, "topic");
		String queueName = channel.queueDeclare().getQueue();
		channel.queueBind(queueName, Constant.TOPIC_NAME, "kernal.*");
		QueueingConsumer consumer = new QueueingConsumer(channel);
		channel.basicConsume(queueName, true, consumer);
		while (true) {
			QueueingConsumer.Delivery delivery = consumer.nextDelivery();
			String message = new String(delivery.getBody());
			String routingKey = delivery.getEnvelope().getRoutingKey();
			System.out.println(" [x] Received routingKey = " + routingKey + ",msg = " + message + ".");
		}
	}

}
